//
//  Animator.swift
//  DYSwiftFramework
//
//  Created by 黄德玉 on 2018/8/16.
//  Copyright © 2018年 none. All rights reserved.
//

import UIKit

class Animator:NSObject,UIViewControllerAnimatedTransitioning {
    
    public var name:String?                                                // 定义几个通用的动画，通过name检索
    public var timeDuration:TimeInterval = 0.5                              // 动画时间
    public var action:((UIViewControllerContextTransitioning,TimeInterval)->())?         // 动画内容，第一个参数是context,第二个参数随意，可以将制定的一些UI或者其他元素加入进去来参加动画
    public var extraPars:Any?                                               // 额外的参数
    public var animationEndAction:((Bool)->Void)?                           // 动画结束的事件
    
    
    
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return timeDuration;
    }
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        if let ac = action {
            ac(transitionContext,timeDuration)
        }
    }
    func animationEnded(_ transitionCompleted: Bool) {
        if let endAction = animationEndAction {
            endAction(transitionCompleted)
        }
    }
    deinit {
        debugPrint("动画控制器释放")
    }

}
